package studentmanage.com.cn;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author Kevin
 * @Data 2021/2/21
 */
public class MainTwo {
    static ArrayList<Student> stu = new ArrayList<>();
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        Welcome();
    }
    public static void Welcome(){
        System.out.println("欢迎进入学生管理系统");
        int choice;
        while(true) {
            System.out.println("1.信息添加");
            System.out.println("2.信息查看");
            System.out.println("3.信息删除");
            System.out.println("4.信息更改");
            System.out.println("0.退出");
            System.out.println("请输入你要进行的操作");
            choice = sc.nextInt();
            switch (choice) {
                case 0:
                    System.exit(0); //退出程序
                case 1:
                    add();
                    break;//添加学生信息
                case 2:
                    show();
                    break;//查询学生信息
                case 3:
                    delete();
                    break;
                case 4:
                    modify();
                    break;
            }
        }
    }
    //添加学生信息
    public static void add(){
        while (true){
            System.out.println("按任意键开始添加学生信息，按0退出添加");
            if(sc.next().equals("0")) break;
            System.out.println("请输入学生的姓名，高数成绩，大物成绩，大英成绩");

            Student s = new Student();
            s.setName(sc.next());
            s.setMathScore(sc.nextFloat());
            s.setPhyScore(sc.nextFloat());
            s.setEngScore(sc.nextFloat());
            stu.add(s);
        }
    }
    /* 显示学生信息 */
    public static void show(){
        System.out.println("**************************************************");
        System.out.println("姓名"+"\t"+"高数"+"\t"+"大物"+"\t"+"大英"+"\t"+"平均分"+"\t"+"等级");
        for (int i = 0; i < stu.size(); i++) {
            Student s = stu.get(i);
            float AvgScore = (s.getMathScore()+s.getPhyScore()+s.getEngScore())/3;
            System.out.println(s.getName()+"\t"+s.getMathScore()+"\t"+s.getPhyScore()
                    +"\t"+s.getEngScore()+"\t"+AvgScore+"\t"+grade(AvgScore));
        }
        System.out.println("**************************************************");

    }
    /* 删除学生信息 */
    public static void delete(){
        System.out.println("请输入要删除学生的姓名：");
        String name = sc.next();
        int flag = -1;
        for (int i = 0; i < stu.size() ; i++) {
            Student s = stu.get(i);
            if (name.equals(s.getName())){
                flag = i;
                break;
            }
        }
        if (flag == -1){
            System.out.println("该学生信息不存在");
        }else{
            stu.remove(flag);
        }
    }
    /* 修改学生信息 */
    public static void modify(){
        System.out.println("请输入要更改学生的姓名");
        String name = sc.next();
        int flag = -1;
        for (int i = 0; i < stu.size(); i++) {
            Student s = stu.get(i);
            if (name.equals(s.getName())){
                flag = i;
                System.out.println("请输入修改的成绩信息");
                s.setMathScore(sc.nextFloat());
                s.setPhyScore(sc.nextFloat());
                s.setEngScore(sc.nextFloat());
            }
        }
        if (flag == -1){
            System.out.println("没有该学生");
        }else{
            System.out.println("修改成功！");
        }
    }
    //判断平均成绩来判断等级
    public static String grade(float Avg){
        if(Avg>=90){
            return ("优秀");
        }else if (Avg>=80){
            return ("良好");
        }else if(Avg>=60){
            return ("还行");
        }else{
            return ("拉胯");
        }
    }

}
